package com.wswy.wyjk.ui.practice

import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.raft.framework.ui.adapter.SampleRecyclerViewAdapter
import com.wswy.wyjk.AppContext
import com.wswy.wyjk.R
import com.wswy.wyjk.model.vo.PracticeModel
import com.wswy.wyjk.ui.widget.RecordStatusTextView
import com.wswy.wyjk.utils.loadLayout
import timber.log.Timber

class RecordAdapter : SampleRecyclerViewAdapter<PracticeModel,RecordAdapter.RecordViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecordViewHolder {
        return RecordViewHolder(loadLayout(parent, R.layout.layout_record_item))
    }

    override fun onBindViewHolder(holder: RecordViewHolder, position: Int, data: PracticeModel?) {
        holder.tvPosition.text = "${position+1}"
        

        data?.let {

            if (it.hasAnswer()){

                if (it.isRight()){
                    holder.tvPosition.setRight()

                }else{
                    holder.tvPosition.setWrong()
                }

            }else{
                holder.tvPosition.setNormal()
            }

        }
    }


    class RecordViewHolder(itemView:View):RecyclerView.ViewHolder(itemView){
        val tvPosition : RecordStatusTextView = itemView.findViewById(R.id.tv_position)
    }

}